﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
namespace Kunlun.BusinessLogic
{
    public static class WebLog
    {
        /// <summary>
        /// 保存错误日志
        /// </summary>
        /// <param name="e"></param>
        public static void ErrorLog(Exception e)
        {
            string temp = System.Configuration.ConfigurationManager.AppSettings["errorlog"];

			if (!Directory.Exists(temp))		//如果不存在改目录
				Directory.CreateDirectory(temp);

            string filename = String.Format("{0}-{1}-{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            //try
            //{

                if (!File.Exists(String.Format("{0}{1}log.txt", @temp, @filename)))
                {
                    FileStream file = File.Create(String.Format("{0}{1}log.txt", temp, filename));
                    file.Dispose();
                }

                StreamWriter m_streamWriter = new StreamWriter(String.Format("{0}{1}log.txt", temp, filename), true);

                m_streamWriter.WriteLine(String.Format("\r\n{0} {1}\r\n{2}\r\n{3}\r\n{4}\r\n", DateTime.Now, e.InnerException, e.Message, e.Source, e));

                m_streamWriter.Flush();
                m_streamWriter.Dispose();
                m_streamWriter.Close();
            //}
            //catch
            //{

            //}

        }

        /// <summary>
        /// 保存错误日志
        /// </summary>
        /// <param name="e"></param>
        /// /// <param name="param">其他参数</param>
        public static void ErrorLog(Exception e,string param)
            {
            string temp = System.Configuration.ConfigurationManager.AppSettings["errorlog"];

            if (!Directory.Exists(temp))		//如果不存在改目录
                Directory.CreateDirectory(temp);

            string filename = String.Format("{0}-{1}-{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            //try
            //{

            if (!File.Exists(String.Format("{0}{1}log.txt", @temp, @filename)))
                {
                FileStream file = File.Create(String.Format("{0}{1}log.txt", temp, filename));
                file.Dispose();
                }

            StreamWriter m_streamWriter = new StreamWriter(String.Format("{0}{1}log.txt", temp, filename), true);
            m_streamWriter.WriteLine(String.Format("参数：{0}\r\n", param));
            m_streamWriter.WriteLine(String.Format("\r\n{0} {1}\r\n{2}\r\n{3}\r\n{4}\r\n", DateTime.Now, e.InnerException, e.Message, e.Source, e));

            m_streamWriter.Flush();
            m_streamWriter.Dispose();
            m_streamWriter.Close();
            //}
            //catch
            //{

            //}

            }
        /// <summary>
        ///用户照片存放物理位置
        /// </summary>
        public static string Photo {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["photo"];
                return _view;
            }
        }
        /// <summary>
        /// 用户照片浏览文件夹位置
        /// </summary>
        public static string PhotoView
        {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["photoview"];
                return _view;
            }
        }
        /// <summary>
        /// 用户作品浏览文件夹位置
        /// </summary>
        public static string WorksView
        {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["worksview"];
                return _view;
            }
        }
        /// <summary>
        /// 用户作品存放物理位置
        /// </summary>
        public static string Works
        {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["works"];
                return _view;
            }
        }
        public static string Temps
        {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["temps"];
                return _view;
            }
        }
        public static string TempsView
        {
            get
            {
                string _view = System.Configuration.ConfigurationManager.AppSettings["tempsview"];
                return _view;
            }
        }

		public static string ImageHttp {
			get {
				return System.Configuration.ConfigurationManager.AppSettings["ImageHttp"];
			}
		}

		public static string DivFrameID {
			get {
				return System.Configuration.ConfigurationManager.AppSettings["FrameID"];
			}
		}

		public static string BorderID {
			get {
				return System.Configuration.ConfigurationManager.AppSettings["BorderID"];
			}
		}

		public static string PaperID {
			get {
				return System.Configuration.ConfigurationManager.AppSettings["PaperID"];
			}
		}
        public static string RegEmail()
        {
            try
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string content = File.ReadAllText(path + "\\Content\\Reg\\Reg.html");
                return content;
            }
            catch(Exception ex )
            {
                WebLog.ErrorLog(ex);
                
                return string.Empty;
            }
        }
    }
}
